﻿using System;
using System.Collections.Generic;

namespace AdaptiveAgents.Distributions
{
    /// <summary>
    /// Represents a Uniform distribution 
    /// </summary>
    public class Uniform : IDistribution
    {

        #region IDistribution Members

        /// <summary>
        /// Gets the mean of the uniform distribution
        /// </summary>
        public double Mean
        {
            get { return 0.5; }
        }

        /// <summary>
        /// Gets the variance
        /// </summary>
        public double Variance
        {
            get { return 1 / 12; }
        }

        /// <summary>
        /// Generates random distribution values
        /// Not implemented in uniform distribution
        /// </summary>
        public void generateRandomValues() { }

        /// <summary>
        /// Gets f(x) (probability density function) ccording to the uniform distribution
        /// </summary>
        /// <param name="x">Random variable</param>
        /// <returns>Always returns 1 because it's uniform distribution</returns>
        public double valueOf(double x)
        {
            return 1;
        }

        /// <summary>
        /// Gets F(x) (probability cumulative density function)
        /// </summary>
        /// <param name="x">Random variable</param>
        /// <returns>F(x) according to the uniform distribution function</returns>
        public double cumulativeValueOf(double x)
        {
            if (x < 0) return 0;
            if (x > 1) return 1;
            
            return x;
        }

        /// <summary>
        /// Gets a sample of the distribution values
        /// </summary>
        /// <returns>Array of points that were sampled from the distribution function</returns>
        public Point[] sample()
        {
            Point[] sample = new Point[2];
            sample[0] = new Point(0, 1);
            sample[1] = new Point(1, 1);

            return sample;
        }

        /// <summary>
        /// Gets the distribution type
        /// </summary>
        public DistributionType Type
        {
            get { return DistributionType.Uniform; }
        }

        /// <summary>
        /// Gets a description of the distribution
        /// </summary>
        /// <returns>String representation of the uniform distribution</returns>
        public String ToString()
        {
            return Type.ToString();
        }

        /// <summary>
        /// Generates random value
        /// </summary>
        /// <returns>return 1</returns>
        public double generateValue()
        {
            return Generator.getNextDouble();
        }

        #endregion
    }
}
